local blaze = require "blaze"
local app = require "app"
local gamelib = require "club.threecard.gamelib"
local game = app.game.running

local M = gamelib.ui.element()

local function update(self, state, getters)
    self.bet_value_txt.text = app.i18n.number(getters.bet_value, "chip2")
    self.bet_max_tip:SetActive(getters.is_max_bet)
end

M.store_watchers = {
    machine = {
        ["$"] = function(self, store, state, args)
            update(self, state, store.getters)
        end,

        ["更新下注档位"] = function(self, store, state, args)
            update(self, state, store.getters)
        end,

        ["改变下注"] = function(self, store, state, args)
            update(self, state, store.getters)
        end,
    }
}

function M:ctor()
    self.res = "club.threecard.slotlib/ui/common.b:bet_viser"
end

function M:on_injected(bind)
    bind("button.click", self.btn_add, self.add_ivk)
    bind("button.click", self.btn_sub, self.sub_ivk)

    app.utility.button_style.highlight_scale(self.btn_add)
    app.utility.button_style.highlight_scale(self.btn_sub)
end

function M:add_ivk()
    app.audio.post("lobby:button down")
    game.store.machine.increase_bet()
    game.store.machine.on_auto(false)
end

function M:sub_ivk()
    app.audio.post("lobby:button down")
    game.store.machine.decrease_bet()
    game.store.machine.on_auto(false)
end

return M